home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / emacs / emacs1857 / src_d2.zoo / source / process.c < prev    next >
C/C++ Source or Header  |  1991-12-02  |  68KB  |  2,512 lines

  1. /* Asynchronous subprocess control for GNU Emacs.
  2.    Copyright (C) 1985, 1986, 1987, 1988, 1990 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include <signal.h>
  22.  
  23. #include "config.h"
  24.  
  25. #ifdef subprocesses
  26. /* The entire file is within this conditional */
  27.  
  28. #include <stdio.h>
  29. #include <errno.h>
  30. #include <setjmp.h>
  31. #include <sys/types.h>        /* some typedefs are used in sys/file.h */
  32. #include <sys/file.h>
  33. #include <sys/stat.h>
  34.  
  35. #ifdef HAVE_SOCKETS    /* TCP connection support, if kernel can do it */
  36. #include <sys/socket.h>
  37. #include <netdb.h>
  38. #include <netinet/in.h>
  39. #endif /* HAVE_SOCKETS */
  40.  
  41. #if defined(BSD) || defined(STRIDE)
  42. #include <sys/ioctl.h>
  43. #if !defined (O_NDELAY) && defined (HAVE_PTYS)
  44. #include <fcntl.h>
  45. #endif /* HAVE_PTYS and no O_NDELAY */
  46. #endif /* BSD or STRIDE */
  47. #ifdef USG
  48. #include <termio.h>
  49. #include <fcntl.h>
  50. #endif /* USG */
  51.  
  52. #ifdef NEED_BSDTTY
  53. #include <sys/bsdtty.h>
  54. #endif
  55.  
  56. #ifdef HPUX
  57. #undef TIOCGPGRP
  58. #endif
  59.  
  60. #ifdef IRIS
  61. #include <sys/sysmacros.h>    /* for "minor" */
  62. #include <sys/time.h>
  63. #else
  64. #ifdef UNIPLUS
  65. #include <sys/time.h>
  66.  
  67. #else /* not IRIS, not UNIPLUS */
  68. #ifdef HAVE_TIMEVAL
  69. /* _h_BSDTYPES is checked because on ISC unix, socket.h includes
  70.    both time.h and sys/time.h, and the latter file is protected
  71.    from repeated inclusion.  */
  72. #if defined(USG) && !defined(AIX) && !defined(_h_BSDTYPES) && !defined(USG_SYS_TIME)
  73. #include <time.h>
  74. #else /* AIX or USG_SYS_TIME, or not USG */
  75. #include <sys/time.h>
  76. #endif /* AIX or USG_SYS_TIME, or not USG */
  77. #endif /* HAVE_TIMEVAL */
  78.  
  79. #endif /* not UNIPLUS */
  80. #endif /* not IRIS */
  81.  
  82. #if defined (HPUX) && defined (HAVE_PTYS)
  83. #include <sys/ptyio.h>
  84. #endif
  85.   
  86. #ifdef AIX
  87. #include <sys/pty.h>
  88. #include <unistd.h>
  89. #endif /* AIX */
  90.  
  91. #ifdef SYSV_PTYS
  92. #include <sys/tty.h>
  93. #include <sys/pty.h>
  94. #endif
  95.  
  96. #undef NULL
  97. #include "lisp.h"
  98. #include "window.h"
  99. #include "buffer.h"
  100. #include "process.h"
  101. #include "termhooks.h"
  102. #include "termopts.h"
  103. #include "commands.h"
  104.  
  105. Lisp_Object Qrun, Qstop, Qsignal, Qexit, Qopen, Qclosed;
  106.  
  107. /* a process object is a network connection when its childp field is neither
  108.    Qt nor Qnil but is instead a string (name of foreign host we
  109.    are connected to + name of port we are connected to) */
  110.  
  111. #ifdef HAVE_SOCKETS
  112. #define NETCONN_P(p) (XGCTYPE (XPROCESS (p)->childp) == Lisp_String)
  113. #else
  114. #define NETCONN_P(p) 0
  115. #endif /* HAVE_SOCKETS */
  116.  
  117. /* Define SIGCHLD as an alias for SIGCLD.  There are many conditionals
  118.    testing SIGCHLD.  */
  119.  
  120. #if !defined (SIGCHLD) && defined (SIGCLD)
  121. #define SIGCHLD SIGCLD
  122. #endif /* SIGCLD */
  123.  
  124. /* Define the structure that the wait system call stores.
  125.    On many systems, there is a structure defined for this.
  126.    But on vanilla-ish USG systems there is not.  */
  127.  
  128. #ifndef WAITTYPE
  129. #if !defined (BSD) && !defined (UNIPLUS) && !defined (STRIDE) && !(defined (HPUX) && !defined (NOMULTIPLEJOBS)) && !defined (HAVE_WAIT_HEADER)
  130. #define WAITTYPE int
  131. #define WIFSTOPPED(w) ((w&0377) == 0177)
  132. #define WIFSIGNALED(w) ((w&0377) != 0177 && (w&~0377) == 0)
  133. #define WIFEXITED(w) ((w&0377) == 0)
  134. #define WRETCODE(w) (w >> 8)
  135. #define WSTOPSIG(w) (w >> 8)
  136. #define WCOREDUMP(w) ((w&0200) != 0)
  137. #define WTERMSIG(w) (w & 0377)
  138. #else
  139. #ifdef BSD4_1
  140. #include <wait.h>
  141. #else
  142. #include <sys/wait.h>
  143. #endif /* not BSD 4.1 */
  144.  
  145. #define WAITTYPE union wait
  146. #define WRETCODE(w) w.w_retcode
  147. #define WCOREDUMP(w) w.w_coredump
  148.  
  149. #ifdef HPUX
  150. /* HPUX version 7 has broken definitions of these.  */
  151. #undef WTERMSIG
  152. #undef WSTOPSIG
  153. #undef WIFSTOPPED
  154. #undef WIFSIGNALED
  155. #undef WIFEXITED
  156. #endif
  157.  
  158. #ifndef WTERMSIG
  159. #define WTERMSIG(w) w.w_termsig
  160. #endif
  161. #ifndef WSTOPSIG
  162. #define WSTOPSIG(w) w.w_stopsig
  163. #endif
  164. #ifndef WIFSTOPPED
  165. #define WIFSTOPPED(w) (WTERMSIG (w) == 0177)
  166. #endif
  167. #ifndef WIFSIGNALED
  168. #define WIFSIGNALED(w) (WTERMSIG (w) != 0177 && (WSTOPSIG (w)) == 0)
  169. #endif
  170. #ifndef WIFEXITED
  171. #define WIFEXITED(w) (WTERMSIG (w) == 0)
  172. #endif
  173. #endif /* BSD or UNIPLUS or STRIDE */
  174. #endif /* no WAITTYPE */
  175.  
  176. extern errno;
  177. extern sys_nerr;
  178. extern char *sys_errlist[];
  179.  
  180. #ifndef BSD4_1
  181. extern char *sys_siglist[];
  182. #else
  183. char *sys_siglist[] =
  184.   {
  185.     "bum signal!!",
  186.     "hangup",
  187.     "interrupt",
  188.     "quit",
  189.     "illegal instruction",
  190.     "trace trap",
  191.     "iot instruction",
  192.     "emt instruction",
  193.     "floating point exception",
  194.     "kill",
  195.     "bus error",
  196.     "segmentation violation",
  197.     "bad argument to system call",
  198.     "write on a pipe with no one to read it",
  199.     "alarm clock",
  200.     "software termination signal from kill",
  201.     "status signal",
  202.     "sendable stop signal not from tty",
  203.     "stop signal from tty",
  204.     "continue a stopped process",
  205.     "child status has changed",
  206.     "background read attempted from control tty",
  207.     "background write attempted from control tty",
  208.     "input record available at control tty",
  209.     "exceeded CPU time limit",
  210.     "exceeded file size limit"
  211.     };
  212. #endif
  213.  
  214. #ifdef vipc
  215.  
  216. #include "vipc.h"
  217. extern int comm_server;
  218. extern int net_listen_address;
  219. #endif /* vipc */
  220.  
  221. /* t means use pty, nil means use a pipe,
  222.    maybe other values to come.  */
  223. Lisp_Object Vprocess_connection_type;
  224.  
  225. #ifdef SKTPAIR
  226. #ifndef HAVE_SOCKETS
  227. #include <sys/socket.h>
  228. #endif
  229. #endif /* SKTPAIR */
  230.  
  231. /* Number of events of change of status of a process.  */
  232. int process_tick;
  233.  
  234. /* Number of events for which the user or sentinel has been notified.  */
  235. int update_tick;
  236.  
  237. int delete_exited_processes;
  238.  
  239. #ifdef FD_SET
  240. /* We could get this from param.h, but better not to depend on finding that.
  241.    And better not to risk that it might define other symbols used in this
  242.    file.  */
  243. #define MAXDESC 64
  244. #define SELECT_TYPE fd_set
  245. #else /* no FD_SET */
  246. #define MAXDESC 32
  247. #define SELECT_TYPE int
  248.  
  249. /* Define the macros to access a single-int bitmap of descriptors.  */
  250. #define FD_SET(n, p) (*(p) |= (1 << (n)))
  251. #define FD_CLR(n, p) (*(p) &= ~(1 << (n)))
  252. #define FD_ISSET(n, p) (*(p) & (1 << (n)))
  253. #define FD_ZERO(p) (*(p) = 0)
  254. #endif /* no FD_SET */
  255.  
  256. /* Mask of bits indicating the descriptors that we wait for input on */
  257.  
  258. SELECT_TYPE input_wait_mask;
  259.  
  260. /* Indexed by descriptor, gives the process (if any) for that descriptor */
  261. Lisp_Object chan_process[MAXDESC];
  262.  
  263. /* Alist of elements (NAME . PROCESS) */
  264. Lisp_Object Vprocess_alist;
  265.  
  266. Lisp_Object Qprocessp;
  267.  
  268. Lisp_Object get_process ();
  269.  
  270. /* Buffered-ahead input char from process, indexed by channel.
  271.    -1 means empty (no char is buffered).
  272.    Used on sys V where the only way to tell if there is any
  273.    output from the process is to read at least one char.
  274.    Always -1 on systems that support FIONREAD.  */
  275.  
  276. int proc_buffered_char[MAXDESC];
  277.  
  278. /* These variables hold the filter about to be run, and its args,
  279.    between read_process_output and run_filter.
  280.    Also used in exec_sentinel for sentinels.  */
  281. Lisp_Object this_filter;
  282. Lisp_Object filter_process, filter_string;
  283.  
  284. /* Compute the Lisp form of the process status, p->status,
  285.    from the numeric status that was returned by `wait'.  */
  286.  
  287. update_status (p)
  288.      struct Lisp_Process *p;
  289. {
  290.   union { int i; WAITTYPE wt; } u;
  291.   u.i = XFASTINT (p->raw_status_low) + (XFASTINT (p->raw_status_high) << 16);
  292.   p->status = status_convert (u.wt);
  293.   p->raw_status_low = Qnil;
  294.   p->raw_status_high = Qnil;
  295. }
  296.  
  297. /* Convert a process status word in Unix format
  298.    to the list that we use internally.  */
  299.  
  300. Lisp_Object
  301. status_convert (w)
  302.      WAITTYPE w;
  303. {
  304.   if (WIFSTOPPED (w))
  305.     return Fcons (Qstop, Fcons (make_number (WSTOPSIG (w)), Qnil));
  306.   else if (WIFEXITED (w))
  307.     return Fcons (Qexit, Fcons (make_number (WRETCODE (w)),
  308.                 WCOREDUMP (w) ? Qt : Qnil));
  309.   else if (WIFSIGNALED (w))
  310.     return Fcons (Qsignal, Fcons (make_number (WTERMSIG (w)),
  311.                   WCOREDUMP (w) ? Qt : Qnil));
  312.   else
  313.     return Qrun;
  314. }
  315.  
  316. /* Given a status-list, extract the three pieces of information
  317.    and store them individually through the three pointers.  */
  318.  
  319. void
  320. decode_status (l, symbol, code, coredump)
  321.      Lisp_Object l;
  322.      Lisp_Object *symbol;
  323.      int *code;
  324.      int *coredump;
  325. {
  326.   Lisp_Object tem;
  327.  
  328.   if (XTYPE (l) == Lisp_Symbol)
  329.     {
  330.       *symbol = l;
  331.       *code = 0;
  332.       *coredump = 0;
  333.     }
  334.   else
  335.     {
  336.       *symbol = XCONS (l)->car;
  337.       tem = XCONS (l)->cdr;
  338.       *code = XFASTINT (XCONS (tem)->car);
  339.       tem = XFASTINT (XCONS (tem)->cdr);
  340.       *coredump = !NULL (tem);
  341.     }
  342. }
  343.  
  344. /* Return a string describing a process status list.  */
  345.  
  346. Lisp_Object 
  347. status_message (status)
  348.      Lisp_Object status;
  349. {
  350.   Lisp_Object symbol;
  351.   int code, coredump;
  352.   Lisp_Object string, string2;
  353.  
  354.   decode_status (status, &symbol, &code, &coredump);
  355.  
  356.   if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
  357.     {
  358.       string = build_string (code < NSIG ? sys_siglist[code] : "unknown");
  359.       string2 = build_string (coredump ? " (core dumped)\n" : "\n");
  360.       XSTRING (string)->data[0] = DOWNCASE (XSTRING (string)->data[0]);
  361.       return concat2 (string, string2);
  362.     }
  363.   else if (EQ (symbol, Qexit))
  364.     {
  365.       if (code == 0)
  366.     return build_string ("finished\n");
  367.       string = Fint_to_string (make_number (code));
  368.       string2 = build_string (coredump ? " (core dumped)\n" : "\n");
  369.       return concat2 (build_string ("exited abnormally with code "),
  370.               concat2 (string, string2));
  371.     }
  372.   else
  373.     return Fcopy_sequence (Fsymbol_name (symbol));
  374. }
  375.  
  376. #ifdef HAVE_PTYS
  377.  
  378. /* Open an available pty, returning a file descriptor.
  379.    Return -1 on failure.
  380.    The file name of the terminal corresponding to the pty
  381.    is left in the variable pty_name.  */
  382.  
  383. char pty_name[24];
  384.  
  385. int
  386. allocate_pty ()
  387. {
  388.   struct stat stb;
  389.   register c, i;
  390.   int fd;
  391.  
  392. #ifdef PTY_ITERATION
  393.   PTY_ITERATION
  394. #else
  395.   for (c = FIRST_PTY_LETTER; c <= 'z'; c++)
  396.     for (i = 0; i < 16; i++)
  397. #endif
  398.       {
  399. #ifdef PTY_NAME_SPRINTF
  400.     PTY_NAME_SPRINTF
  401. #else
  402. #ifdef HPUX
  403.     sprintf (pty_name, "/dev/ptym/pty%c%x", c, i);
  404. #else
  405. #ifdef RTU
  406.     sprintf (pty_name, "/dev/pty%x", i);
  407. #else
  408.     sprintf (pty_name, "/dev/pty%c%x", c, i);
  409. #endif /* not RTU */
  410. #endif /* not HPUX */
  411. #endif /* no PTY_NAME_SPRINTF */
  412.  
  413. #ifndef IRIS
  414.     if (stat (pty_name, &stb) < 0)
  415.       return -1;
  416. #ifdef O_NONBLOCK
  417.     fd = open (pty_name, O_RDWR | O_NONBLOCK, 0);
  418. #else
  419.     fd = open (pty_name, O_RDWR | O_NDELAY, 0);
  420. #endif
  421. #else /* Unusual IRIS code */
  422.      fd = open ("/dev/ptc", O_RDWR | O_NDELAY, 0);
  423.      if (fd < 0)
  424.        return -1;
  425.     if (fstat (fd, &stb) < 0)
  426.       return -1;
  427. #endif /* IRIS */
  428.  
  429.     if (fd >= 0)
  430.       {
  431.         /* check to make certain that both sides are available
  432.            this avoids a nasty yet stupid bug in rlogins */
  433. #ifdef PTY_TTY_NAME_SPRINTF
  434.         PTY_TTY_NAME_SPRINTF
  435. #else
  436.         /* In version 19, make these special cases use the macro above.  */
  437. #ifdef HPUX
  438.             sprintf (pty_name, "/dev/pty/tty%c%x", c, i);
  439. #else
  440. #ifdef RTU
  441.             sprintf (pty_name, "/dev/ttyp%x", i);
  442. #else
  443. #ifdef IRIS
  444.          sprintf (pty_name, "/dev/ttyq%d", minor (stb.st_rdev));
  445. #else
  446.             sprintf (pty_name, "/dev/tty%c%x", c, i);
  447. #endif /* not IRIS */
  448. #endif /* not RTU */
  449. #endif /* not HPUX */
  450. #endif /* no PTY_TTY_NAME_SPRINTF */
  451. #ifndef UNIPLUS
  452.         if (access (pty_name, 6) != 0)
  453.           {
  454.         close (fd);
  455. #ifndef IRIS
  456.         continue;
  457. #else
  458.         return -1;
  459. #endif /* IRIS */
  460.           }
  461. #endif /* not UNIPLUS */
  462.         setup_pty (fd);
  463.         return fd;
  464.       }
  465.       }
  466.   return -1;
  467. }
  468. #endif /* HAVE_PTYS */
  469.  
  470. Lisp_Object
  471. make_process (name)
  472.      Lisp_Object name;
  473. {
  474.   register Lisp_Object val, tem, name1;
  475.   register struct Lisp_Process *p;
  476.   char suffix[10];
  477.   register int i;
  478.  
  479.   /* size of process structure includes the vector header,
  480.      so deduct for that.  But struct Lisp_Vector includes the first
  481.      element, thus deducts too much, so add it back.  */
  482.   val = Fmake_vector (make_number ((sizeof (struct Lisp_Process)
  483.                     - sizeof (struct Lisp_Vector)
  484.                     + sizeof (Lisp_Object))
  485.                    / sizeof (Lisp_Object)),
  486.               Qnil);
  487.   XSETTYPE (val, Lisp_Process);
  488.  
  489.   p = XPROCESS (val);
  490.   XFASTINT (p->infd) = 0;
  491.   XFASTINT (p->outfd) = 0;
  492.   XFASTINT (p->pid) = 0;
  493.   XFASTINT (p->tick) = 0;
  494.   XFASTINT (p->update_tick) = 0;
  495.   p->raw_status_low = Qnil;
  496.   p->raw_status_high = Qnil;
  497.   p->status = Qrun;
  498.   p->mark = Fmake_marker ();
  499.  
  500.   /* If name is already in use, modify it until it is unused.  */
  501.  
  502.   name1 = name;
  503.   for (i = 1; ; i++)
  504.     {
  505.       tem = Fget_process (name1);
  506.       if (NULL (tem)) break;
  507.       sprintf (suffix, "<%d>", i);
  508.       name1 = concat2 (name, build_string (suffix));
  509.     }
  510.   name = name1;
  511.   p->name = name;
  512.   Vprocess_alist = Fcons (Fcons (name, val), Vprocess_alist);
  513.   return val;
  514. }
  515.  
  516. remove_process (proc)
  517.      register Lisp_Object proc;
  518. {
  519.   register Lisp_Object pair;
  520.  
  521.   pair = Frassq (proc, Vprocess_alist);
  522.   Vprocess_alist = Fdelq (pair, Vprocess_alist);
  523.   Fset_marker (XPROCESS (proc)->mark, Qnil, Qnil);
  524.  
  525.   deactivate_process (proc);
  526. }
  527.  
  528. DEFUN ("processp", Fprocessp, Sprocessp, 1, 1, 0,
  529.   "Return t if OBJECT is a process.")
  530.   (obj)
  531.      Lisp_Object obj;
  532. {
  533.   return XTYPE (obj) == Lisp_Process ? Qt : Qnil;
  534. }
  535.  
  536. DEFUN ("get-process", Fget_process, Sget_process, 1, 1, 0,
  537.   "Return the process named NAME, or nil if there is none.")
  538.   (name)
  539.      register Lisp_Object name;
  540. {
  541.   if (XTYPE (name) == Lisp_Process)
  542.     return name;
  543.   CHECK_STRING (name, 0);
  544.   return Fcdr (Fassoc (name, Vprocess_alist));
  545. }
  546.  
  547. DEFUN ("get-buffer-process", Fget_buffer_process, Sget_buffer_process, 1, 1, 0,
  548.   "Return the (or, a) process associated with BUFFER.\n\
  549. BUFFER may be a buffer or the name of one.")
  550.   (name)
  551.      register Lisp_Object name;
  552. {
  553.   register Lisp_Object buf, tail, proc;
  554.  
  555.   if (NULL (name)) return Qnil;
  556.   buf = Fget_buffer (name);
  557.   if (NULL (buf)) return Qnil;
  558.  
  559.   for (tail = Vprocess_alist; !NULL (tail); tail = Fcdr (tail))
  560.     {
  561.       proc = Fcdr (Fcar (tail));
  562.       if (XTYPE (proc) == Lisp_Process && EQ (XPROCESS (proc)->buffer, buf))
  563.     return proc;
  564.     }
  565.   return Qnil;
  566. }
  567.  
  568. /* This is how commands for the user decode process arguments */
  569.  
  570. Lisp_Object
  571. get_process (name)
  572.      register Lisp_Object name;
  573. {
  574.   register Lisp_Object proc;
  575.   if (NULL (name))
  576.     proc = Fget_buffer_process (Fcurrent_buffer ());
  577.   else
  578.     {
  579.       proc = Fget_process (name);
  580.       if (NULL (proc))
  581.     proc = Fget_buffer_process (Fget_buffer (name));
  582.     }
  583.  
  584.   if (!NULL (proc))
  585.     return proc;
  586.  
  587.   if (NULL (name))
  588.     error ("Current buffer has no process");
  589.   else
  590.     error ("Process %s does not exist", XSTRING (name)->data);
  591.   /* NOTREACHED */
  592. }
  593.  
  594. DEFUN ("delete-process", Fdelete_process, Sdelete_process, 1, 1, 0,
  595.   "Delete PROCESS: kill it and forget about it immediately.\n\
  596. PROCESS may be a process or the name of one, or a buffer name.")
  597.   (proc)
  598.      register Lisp_Object proc;
  599. {
  600.   proc = get_process (proc);
  601.   XPROCESS (proc)->raw_status_low = Qnil;
  602.   XPROCESS (proc)->raw_status_high = Qnil;
  603.   if (NETCONN_P (proc))
  604.     {
  605.       XPROCESS (proc)->status = Fcons (Qexit, Fcons (make_number (0), Qnil));
  606.       XSETINT (XPROCESS (proc)->tick, ++process_tick);
  607.     }
  608.   else if (XFASTINT (XPROCESS (proc)->infd))
  609.     {
  610.       Fkill_process (proc, Qnil);
  611.       /* Do this now, since remove_process will make sigchld_handler do nothing.  */
  612.       XPROCESS (proc)->status
  613.     = Fcons (Qsignal, Fcons (make_number (SIGKILL), Qnil));
  614.       XSETINT (XPROCESS (proc)->tick, ++process_tick);
  615.       status_notify ();
  616.     }
  617.   remove_process (proc);
  618.   return Qnil;
  619. }
  620.  
  621. DEFUN ("process-status", Fprocess_status, Sprocess_status, 1, 1, 0,
  622.   "Return the status of PROCESS: a symbol, one of these:\n\
  623. run  -- for a process that is running.\n\
  624. stop -- for a process stopped but continuable.\n\
  625. exit -- for a process that has exited.\n\
  626. signal -- for a process that has got a fatal signal.\n\
  627. open -- for a network stream connection that is open.\n\
  628. closed -- for a network stream connection that is closed.\n\
  629. nil -- if arg is a process name and no such process exists.")
  630. /* command -- for a command channel opened to Emacs by another process.\n\
  631.    external -- for an i/o channel opened to Emacs by another process.\n\  */
  632.   (proc)
  633.      register Lisp_Object proc;
  634. {
  635.   register struct Lisp_Process *p;
  636.   proc = Fget_process (proc);
  637.   if (NULL (proc))
  638.     return proc;
  639.   p = XPROCESS (proc);
  640.   if (!NULL (p->raw_status_low))
  641.     update_status (p);
  642.   if (XTYPE (p->status) == Lisp_Cons)
  643.     return XCONS (p->status)->car;
  644.   return p->status;
  645. }
  646.  
  647. DEFUN ("process-exit-status", Fprocess_exit_status, Sprocess_exit_status,
  648.        1, 1, 0,
  649.   "Return the exit status of PROCESS or the signal number that killed it.\n\
  650. If PROCESS has not yet exited or died, return 0.")
  651.   (proc)
  652.      register Lisp_Object proc;
  653. {
  654.   CHECK_PROCESS (proc, 0);
  655.   if (!NULL (XPROCESS (proc)->raw_status_low))
  656.     update_status (XPROCESS (proc));
  657.   if (XTYPE (XPROCESS (proc)->status) == Lisp_Cons)
  658.     return XCONS (XCONS (XPROCESS (proc)->status)->cdr)->car;
  659.   return make_number (0);
  660. }
  661.  
  662. DEFUN ("process-id", Fprocess_id, Sprocess_id, 1, 1, 0,
  663.   "Return the process id of PROCESS.\n\
  664. This is the pid of the Unix process which PROCESS uses or talks to.\n\
  665. For a network connection, this value is nil.")
  666.   (proc)
  667.      register Lisp_Object proc;
  668. {
  669.   CHECK_PROCESS (proc, 0);
  670.   return XPROCESS (proc)->pid;
  671. }
  672.  
  673. DEFUN ("process-name", Fprocess_name, Sprocess_name, 1, 1, 0,
  674.   "Return the name of PROCESS, as a string.\n\
  675. This is the name of the program invoked in PROCESS,\n\
  676. possibly modified to make it unique among process names.")
  677.   (proc)
  678.      register Lisp_Object proc;
  679. {
  680.   CHECK_PROCESS (proc, 0);
  681.   return XPROCESS (proc)->name;
  682. }
  683.  
  684. DEFUN ("process-command", Fprocess_command, Sprocess_command, 1, 1, 0,
  685.   "Return the command that was executed to start PROCESS.\n\
  686. This is a list of strings, the first string being the program executed\n\
  687. and the rest of the strings being the arguments given to it.\n\
  688. For a non-child channel, this is nil.")
  689.   (proc)
  690.      register Lisp_Object proc;
  691. {
  692.   CHECK_PROCESS (proc, 0);
  693.   return XPROCESS (proc)->command;
  694. }
  695.  
  696. DEFUN ("set-process-buffer", Fset_process_buffer, Sset_process_buffer,
  697.   2, 2, 0,
  698.   "Set buffer associated with PROCESS to BUFFER (a buffer, or nil).")
  699.   (proc, buffer)
  700.      register Lisp_Object proc, buffer;
  701. {
  702.   CHECK_PROCESS (proc, 0);
  703.   if (!NULL (buffer))
  704.     CHECK_BUFFER (buffer, 1);
  705.   XPROCESS (proc)->buffer = buffer;
  706.   return buffer;
  707. }
  708.  
  709. DEFUN ("process-buffer", Fprocess_buffer, Sprocess_buffer,
  710.   1, 1, 0,
  711.   "Return the buffer PROCESS is associated with.\n\
  712. Output from PROCESS is inserted in this buffer\n\
  713. unless PROCESS has a filter.")
  714.   (proc)
  715.      register Lisp_Object proc;
  716. {
  717.   CHECK_PROCESS (proc, 0);
  718.   return XPROCESS (proc)->buffer;
  719. }
  720.  
  721. DEFUN ("process-mark", Fprocess_mark, Sprocess_mark,
  722.   1, 1, 0,
  723.   "Return the marker for the end of the last output from PROCESS.")
  724.   (proc)
  725.      register Lisp_Object proc;
  726. {
  727.   CHECK_PROCESS (proc, 0);
  728.   return XPROCESS (proc)->mark;
  729. }
  730.  
  731. DEFUN ("set-process-filter", Fset_process_filter, Sset_process_filter,
  732.   2, 2, 0,
  733.   "Give PROCESS the filter function FILTER; nil means no filter.\n\
  734. When a process has a filter, each time it does output\n\
  735. the entire string of output is passed to the filter.\n\
  736. The filter gets two arguments: the process and the string of output.\n\
  737. If the process has a filter, its buffer is not used for output.")
  738.   (proc, filter)
  739.      register Lisp_Object proc, filter;
  740. {
  741.   CHECK_PROCESS (proc, 0);
  742.   XPROCESS (proc)->filter = filter;
  743.   return filter;
  744. }
  745.  
  746. DEFUN ("process-filter", Fprocess_filter, Sprocess_filter,
  747.   1, 1, 0,
  748.   "Returns the filter function of PROCESS; nil if none.\n\
  749. See set-process-filter for more info on filter functions.")
  750.   (proc)
  751.      register Lisp_Object proc;
  752. {
  753.   CHECK_PROCESS (proc, 0);
  754.   return XPROCESS (proc)->filter;
  755. }
  756.  
  757. DEFUN ("set-process-sentinel", Fset_process_sentinel, Sset_process_sentinel,
  758.   2, 2, 0,
  759.   "Give PROCESS the sentinel SENTINEL; nil for none.\n\
  760. The sentinel is called as a function when the process changes state.\n\
  761. It gets two arguments: the process, and a string describing the change.")
  762.   (proc, sentinel)
  763.      register Lisp_Object proc, sentinel;
  764. {
  765.   CHECK_PROCESS (proc, 0);
  766.   XPROCESS (proc)->sentinel = sentinel;
  767.   return sentinel;
  768. }
  769.  
  770. DEFUN ("process-sentinel", Fprocess_sentinel, Sprocess_sentinel,
  771.   1, 1, 0,
  772.   "Return the sentinel of PROCESS; nil if none.\n\
  773. See set-process-sentinel for more info on sentinels.")
  774.   (proc)
  775.      register Lisp_Object proc;
  776. {
  777.   CHECK_PROCESS (proc, 0);
  778.   return XPROCESS (proc)->sentinel;
  779. }
  780.  
  781. DEFUN ("process-kill-without-query", Fprocess_kill_without_query,
  782.   Sprocess_kill_without_query, 1, 2, 0,
  783.   "Say no query needed if PROCESS is running when Emacs is exited.\n\
  784. Optional second argument if non-nil says to require a query.\n\
  785. Value is t if a query was formerly required.")
  786.   (proc, value)
  787.      register Lisp_Object proc, value;
  788. {
  789.   Lisp_Object tem;
  790.   CHECK_PROCESS (proc, 0);
  791.   tem = XPROCESS (proc)->kill_without_query;
  792.   XPROCESS (proc)->kill_without_query = Fnull (value);
  793.   return Fnull (tem);
  794. }
  795.  
  796. Lisp_Object
  797. list_processes_1 ()
  798. {
  799.   register Lisp_Object tail, tem;
  800.   Lisp_Object proc, minspace, tem1;
  801.   register struct buffer *old = current_buffer;
  802.   register struct Lisp_Process *p;
  803.   register int state;
  804.   char tembuf[80];
  805.  
  806.   XFASTINT (minspace) = 1;
  807.  
  808.   set_buffer_internal (XBUFFER (Vstandard_output));
  809.   Fbuffer_flush_undo (Vstandard_output);
  810.  
  811.   current_buffer->truncate_lines = Qt;
  812.  
  813.   write_string ("\
  814. Proc         Status   Buffer         Command\n\
  815. ----         ------   ------         -------\n", -1);
  816.  
  817.   for (tail = Vprocess_alist; !NULL (tail); tail = Fcdr (tail))
  818.     {
  819.       Lisp_Object symbol;
  820.  
  821.       proc = Fcdr (Fcar (tail));
  822.       p = XPROCESS (proc);
  823.       if (NULL (p->childp))
  824.     continue;
  825.  
  826.       Finsert (1, &p->name);
  827.       Findent_to (make_number (13), minspace);
  828.  
  829.       if (!NULL (p->raw_status_low))
  830.     update_status (p);
  831.       symbol = p->status;
  832.       if (XTYPE (p->status) == Lisp_Cons)
  833.     symbol = XCONS (p->status)->car;
  834.  
  835.       if (EQ (symbol, Qsignal))
  836.     {
  837.       Lisp_Object tem;
  838.       tem = Fcar (Fcdr (p->status));
  839.       if (XINT (tem) < NSIG)
  840.         write_string (sys_siglist [XINT (tem)], -1);
  841.       else
  842.         Fprinc (symbol, Qnil);
  843.     }
  844.       else
  845.     Fprinc (symbol, Qnil);
  846.  
  847.       if (EQ (symbol, Qexit))
  848.     {
  849.       Lisp_Object tem;
  850.       tem = Fcar (Fcdr (p->status));
  851.       if (XFASTINT (tem))
  852.         {
  853.           sprintf (tembuf, " %d", XFASTINT (tem));
  854.           write_string (tembuf, -1);
  855.         }
  856.     }
  857.  
  858.       if (EQ (symbol, Qsignal) || EQ (symbol, Qexit))
  859.     remove_process (proc);
  860.  
  861.       Findent_to (make_number (22), minspace);
  862.       if (NULL (p->buffer))
  863.     InsStr ("(none)");
  864.       else if (NULL (XBUFFER (p->buffer)->name))
  865.     InsStr ("(Killed)");
  866.       else
  867.     Finsert (1, &XBUFFER (p->buffer)->name);
  868.  
  869.       Findent_to (make_number (37), minspace);
  870.  
  871.       if (NETCONN_P (proc))
  872.         {
  873.       sprintf (tembuf, "(network stream connection to %s)\n",
  874.            XSTRING (p->childp)->data);
  875.       InsStr (tembuf);
  876.         }
  877.       else 
  878.     {
  879.       tem = p->command;
  880.       while (1)
  881.         {
  882.           tem1 = Fcar (tem);
  883.           Finsert (1, &tem1);
  884.           tem = Fcdr (tem);
  885.           if (NULL (tem))
  886.         break;
  887.           InsStr (" ");
  888.         }
  889.       InsStr ("\n");
  890.        }
  891.     }
  892.  
  893.   return Qnil;
  894. }
  895.  
  896. DEFUN ("list-processes", Flist_processes, Slist_processes, 0, 0, "",
  897.   "Display a list of all processes.\n\
  898. \(Any processes listed as Exited or Signaled are actually eliminated\n\
  899. after the listing is made.)")
  900.   ()
  901. {
  902.   internal_with_output_to_temp_buffer ("*Process List*",
  903.                        list_processes_1, Qnil);
  904.   return Qnil;
  905. }
  906.  
  907. DEFUN ("process-list", Fprocess_list, Sprocess_list, 0, 0, 0,
  908.   "Return a list of all processes.")
  909.   ()
  910. {
  911.   return Fmapcar (Qcdr, Vprocess_alist);
  912. }
  913.  
  914. DEFUN ("start-process", Fstart_process, Sstart_process, 3, MANY, 0,
  915.   "Start a program in a subprocess.  Return the process object for it.\n\
  916. Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS\n\
  917. NAME is name for process.  It is modified if necessary to make it unique.\n\
  918. BUFFER is the buffer or (buffer-name) to associate with the process.\n\
  919.  Process output goes at end of that buffer, unless you specify\n\
  920.  an output stream or filter function to handle the output.\n\
  921.  BUFFER may be also nil, meaning that this process is not associated\n\
  922.  with any buffer\n\
  923. Third arg is program file name.  It is searched for as in the shell.\n\
  924. Remaining arguments are strings to give program as arguments.")
  925.   (nargs, args)
  926.      int nargs;
  927.      register Lisp_Object *args;
  928. {
  929.   Lisp_Object buffer, name, program, proc, tem;
  930.   register unsigned char **new_argv;
  931.   register int i;
  932.  
  933.   buffer = args[1];
  934.   if (!NULL (buffer))
  935.     buffer = Fget_buffer_create (buffer);
  936.  
  937.   name = args[0];
  938.   CHECK_STRING (name, 0);
  939.  
  940.   program = args[2];
  941.  
  942.   CHECK_STRING (program, 2);
  943.  
  944.   new_argv = (unsigned char **) alloca ((nargs - 1) * sizeof (char *));
  945.  
  946.   for (i = 3; i < nargs; i++)
  947.     {
  948.       tem = args[i];
  949.       CHECK_STRING (tem, i);
  950.       new_argv[i - 2] = XSTRING (tem)->data;
  951.     }
  952.   new_argv[i - 2] = 0;
  953.   new_argv[0] = XSTRING (program)->data;
  954.  
  955.   /* If program file name is not absolute, search our path for it */
  956.   if (new_argv[0][0] != '/')
  957.     {
  958.       tem = Qnil;
  959.       openp (Vexec_path, program, "", &tem, 1);
  960.       if (NULL (tem))
  961.     report_file_error ("Searching for program", Fcons (program, Qnil));
  962.       new_argv[0] = XSTRING (tem)->data;
  963.     }
  964.  
  965.   proc = make_process (name);
  966.  
  967.   XPROCESS (proc)->childp = Qt;
  968.   XPROCESS (proc)->command_channel_p = Qnil;
  969.   XPROCESS (proc)->buffer = buffer;
  970.   XPROCESS (proc)->sentinel = Qnil;
  971.   XPROCESS (proc)->filter = Qnil;
  972.   XPROCESS (proc)->command = Flist (nargs - 2, args + 2);
  973.  
  974.   create_process (proc, new_argv);
  975.  
  976.   return proc;
  977. }
  978.  
  979. create_process_1 (signo)
  980.      int signo;
  981. {
  982. #ifdef USG
  983.   /* USG systems forget handlers when they are used;
  984.      must reestablish each time */
  985.   signal (signo, create_process_1);
  986. #endif /* USG */
  987. }
  988.  
  989. #if 0  /* This doesn't work; see the note before sigchld_handler.  */
  990. #ifdef USG
  991. #ifdef SIGCHLD
  992. /* Mimic blocking of signals on system V, which doesn't really have it.  */
  993.  
  994. /* Nonzero means we got a SIGCHLD when it was supposed to be blocked.  */
  995. int sigchld_deferred;
  996.  
  997. create_process_sigchld ()
  998. {
  999.   signal (SIGCHLD, create_process_sigchld);
  1000.  
  1001.   sigchld_deferred = 1;
  1002. }
  1003. #endif
  1004. #endif
  1005. #endif
  1006.  
  1007. create_process (process, new_argv)
  1008.      Lisp_Object process;
  1009.      char **new_argv;
  1010. {
  1011.   int pid, inchannel, outchannel, forkin, forkout;
  1012.   int sv[2];
  1013. #ifdef SIGCHLD
  1014.   int (*sigchld)();
  1015. #endif
  1016.   char **env;
  1017.   int pty_flag = 0;
  1018.   extern char **environ;
  1019.  
  1020. #ifdef MAINTAIN_ENVIRONMENT
  1021.   env = (char **) alloca (size_of_current_environ ());
  1022.   get_current_environ (env);
  1023. #else
  1024.   env = environ;
  1025. #endif /* MAINTAIN_ENVIRONMENT */
  1026.  
  1027.   inchannel = outchannel = -1;
  1028.  
  1029. #ifdef HAVE_PTYS
  1030.   if (EQ (Vprocess_connection_type, Qt))
  1031.     outchannel = inchannel = allocate_pty ();
  1032.  
  1033.   if (inchannel >= 0)
  1034.     {
  1035. #ifndef USG
  1036.       /* On USG systems it does not work to open
  1037.      the pty's tty here and then close and reopen it in the child.  */
  1038.       forkout = forkin = open (pty_name, O_RDWR, 0);
  1039.       if (forkin < 0)
  1040.     report_file_error ("Opening pty", Qnil);
  1041. #else
  1042.       forkin = forkout = -1;
  1043. #endif
  1044.       pty_flag = 1;
  1045.     }
  1046.   else
  1047. #endif /* HAVE_PTYS */
  1048. #ifdef SKTPAIR
  1049.     {
  1050.       if (socketpair (AF_UNIX, SOCK_STREAM, 0, sv) < 0)
  1051.     report_file_error ("Opening socketpair", Qnil);
  1052.       outchannel = inchannel = sv[0];
  1053.       forkout = forkin = sv[1];
  1054.     }
  1055. #else /* not SKTPAIR */
  1056.     {
  1057.       pipe (sv);
  1058.       inchannel = sv[0];
  1059.       forkout = sv[1];
  1060.       pipe (sv);
  1061.       outchannel = sv[1];
  1062.       forkin = sv[0];
  1063.     }
  1064. #endif /* not SKTPAIR */
  1065.  
  1066. #if 0
  1067.   /* Replaced by close_process_descs */
  1068.   set_exclusive_use (inchannel);
  1069.   set_exclusive_use (outchannel);
  1070. #endif
  1071.  
  1072. /* Stride people say it's a mystery why this is needed
  1073.    as well as the O_NDELAY, but that it fails without this.  */
  1074. #ifdef STRIDE
  1075.   {
  1076.     int one = 1;
  1077.     ioctl (inchannel, FIONBIO, &one);
  1078.   }
  1079. #endif
  1080.  
  1081. #ifdef O_NONBLOCK
  1082.   fcntl (inchannel, F_SETFL, O_NONBLOCK);
  1083. #else
  1084. #ifdef O_NDELAY
  1085.   fcntl (inchannel, F_SETFL, O_NDELAY);
  1086. #endif
  1087. #endif
  1088.  
  1089.   /* Record this as an active process, with its channels.
  1090.      As a result, child_setup will close Emacs's side of the pipes.  */
  1091.   chan_process[inchannel] = process;
  1092.   XFASTINT (XPROCESS (process)->infd) = inchannel;
  1093.   XFASTINT (XPROCESS (process)->outfd) = outchannel;
  1094.   XPROCESS (process)->pty_flag = (pty_flag ? Qt : Qnil);
  1095.   XPROCESS (process)->status = Qrun;
  1096.  
  1097.   /* Delay interrupts until we have a chance to store
  1098.      the new fork's pid in its process structure */
  1099. #ifdef SIGCHLD
  1100. #ifdef BSD4_1
  1101.   sighold (SIGCHLD);
  1102. #else /* not BSD4_1 */
  1103. #ifdef HPUX
  1104.   sigsetmask (1 << (SIGCHLD - 1));
  1105. #else /* not HPUX */
  1106. #if defined (BSD) || defined (UNIPLUS)
  1107.   sigsetmask (1 << (SIGCHLD - 1));
  1108. #else /* ordinary USG */
  1109. #if 0
  1110.   sigchld_deferred = 0;
  1111.   sigchld = (int (*)()) signal (SIGCHLD, create_process_sigchld);
  1112. #endif
  1113. #endif /* ordinary USG */
  1114. #endif /* not HPUX */
  1115. #endif /* not BSD4_1 */
  1116. #endif /* SIGCHLD */
  1117.  
  1118.   /* Until we store the proper pid, enable sigchld_handler
  1119.      to recognize an unknown pid as standing for this process.  */
  1120.   XSETINT (XPROCESS (process)->pid, -1);
  1121.  
  1122.   {
  1123.     /* child_setup must clobber environ on systems with true vfork.
  1124.        Protect it from permanent change.  */
  1125.     char **save_environ = environ;
  1126.  
  1127.     pid = vfork ();
  1128.     if (pid == 0)
  1129.       {
  1130.     int xforkin = forkin;
  1131.     int xforkout = forkout;
  1132.  
  1133. #if 0 /* This was probably a mistake--it duplicates code later on,
  1134.      but fails to handle all the cases.  */
  1135.     /* Make SIGCHLD work again in the child.  */
  1136.     sigsetmask (0);
  1137. #endif
  1138.  
  1139.     /* Make the pty be the controlling terminal of the process.  */
  1140. #ifdef HAVE_PTYS
  1141.     /* First, disconnect its current controlling terminal.  */
  1142. #ifdef HAVE_SETSID
  1143.     setsid ();
  1144. #else /* not HAVE_SETSID */
  1145. #ifdef USG
  1146.     /* It's very important to call setpgrp() here and no time
  1147.        afterwards.  Otherwise, we lose our controlling tty which
  1148.        is set when we open the pty. */
  1149.     setpgrp ();
  1150. #endif /* USG */
  1151. #endif /* not HAVE_SETSID */
  1152. #ifdef TIOCNOTTY
  1153.     /* In 4.3BSD, the TIOCSPGRP bug has been fixed, and now you
  1154.        can do TIOCSPGRP only to the process's controlling tty.  */
  1155.     if (pty_flag)
  1156.       {
  1157.         /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here? 
  1158.            I can't test it since I don't have 4.3.  */
  1159.         int j = open ("/dev/tty", O_RDWR, 0);
  1160.         ioctl (j, TIOCNOTTY, 0);
  1161.         close (j);
  1162. #ifndef USG
  1163.         /* In order to get a controlling terminal on some versions
  1164.            of BSD, it is necessary to put the process in pgrp 0
  1165.            before it opens the terminal.  */
  1166.         setpgrp (0, 0);
  1167. #endif
  1168.       }
  1169. #endif /* TIOCNOTTY */
  1170.  
  1171. #if !defined (RTU) && !defined (UNIPLUS)
  1172. /*** There is a suggestion that this ought to be a
  1173.      conditional on TIOCSPGRP.  */
  1174.     /* Now close the pty (if we had it open) and reopen it.
  1175.        This makes the pty the controlling terminal of the subprocess.  */
  1176.     if (pty_flag)
  1177.       {
  1178.         /* I wonder if close (open (pty_name, ...)) would work?  */
  1179.         if (xforkin >= 0)
  1180.           close (xforkin);
  1181.         xforkout = xforkin = open (pty_name, O_RDWR, 0);
  1182.  
  1183.         if (xforkin < 0)
  1184.           abort ();
  1185.       }
  1186. #endif /* not UNIPLUS and not RTU */
  1187. #ifdef SETUP_SLAVE_PTY
  1188.     SETUP_SLAVE_PTY;
  1189. #endif /* SETUP_SLAVE_PTY */
  1190. #ifdef AIX
  1191.     /* On AIX, we've disabled SIGHUP above once we start a child on a pty.
  1192.        Now reenable it in the child, so it will die when we want it to.  */
  1193.     if (pty_flag)
  1194.       signal (SIGHUP, SIG_DFL);
  1195. #endif
  1196. #endif /* HAVE_PTYS */
  1197. #ifdef SIGCHLD
  1198. #ifdef BSD4_1
  1199.     sigrelse (SIGCHLD);
  1200. #else /* not BSD4_1 */
  1201. #if defined (BSD) || defined (UNIPLUS) || defined (HPUX)
  1202.     sigsetmask (0);
  1203. #else /* ordinary USG */
  1204.     signal (SIGCHLD, sigchld);
  1205. #endif /* ordinary USG */
  1206. #endif /* not BSD4_1 */
  1207. #endif /* SIGCHLD */
  1208.     child_setup_tty (xforkout);
  1209.     child_setup (xforkin, xforkout, xforkout, new_argv, env);
  1210.       }
  1211.     environ = save_environ;
  1212.   }
  1213.  
  1214.   if (pid < 0)
  1215.     {
  1216.       remove_process (process);
  1217.       report_file_error ("Doing vfork", Qnil);
  1218.     }
  1219.  
  1220.   XFASTINT (XPROCESS (process)->pid) = pid;
  1221.  
  1222.   FD_SET (inchannel, &input_wait_mask);
  1223.  
  1224.   /* If the subfork execv fails, and it exits,
  1225.      this close hangs.  I don't know why.
  1226.      So have an interrupt jar it loose.  */
  1227.   stop_polling ();
  1228.   signal (SIGALRM, create_process_1);
  1229.   alarm (1);
  1230.   if (forkin >= 0)
  1231.     close (forkin);
  1232.   alarm (0);
  1233.   start_polling ();
  1234.   if (forkin != forkout && forkout >= 0)
  1235.     close (forkout);
  1236.  
  1237. #ifdef SIGCHLD
  1238. #ifdef BSD4_1
  1239.   sigrelse (SIGCHLD);
  1240. #else /* not BSD4_1 */
  1241. #if defined (BSD) || defined (UNIPLUS) || defined (HPUX)
  1242.   sigsetmask (0);
  1243. #else /* ordinary USG */
  1244. #if 0
  1245.   signal (SIGCHLD, sigchld);
  1246.   /* Now really handle any of these signals
  1247.      that came in during this function.  */
  1248.   if (sigchld_deferred)
  1249.     kill (getpid (), SIGCHLD);
  1250. #endif
  1251. #endif /* ordinary USG */
  1252. #endif /* not BSD4_1 */
  1253. #endif /* SIGCHLD */
  1254. }
  1255.  
  1256. #ifdef HAVE_SOCKETS
  1257.  
  1258. /* open a TCP network connection to a given HOST/SERVICE.  Treated
  1259.    exactly like a normal process when reading and writing.  Only
  1260.    differences are in status display and process deletion.  A network
  1261.    connection has no PID; you cannot signal it.  All you can do is
  1262.    deactivate and close it via delete-process */
  1263.  
  1264. DEFUN ("open-network-stream", Fopen_network_stream, Sopen_network_stream, 
  1265.        4, 4, 0, 
  1266.   "Open a TCP connection for a service to a host.\n\
  1267. Returns a subprocess-object to represent the connection.\n\
  1268. Input and output work as for subprocesses; `delete-process' closes it.\n\
  1269. Args are NAME BUFFER HOST SERVICE.\n\
  1270. NAME is name for process.  It is modified if necessary to make it unique.\n\
  1271. BUFFER is the buffer (or buffer-name) to associate with the process.\n\
  1272.  Process output goes at end of that buffer, unless you specify\n\
  1273.  an output stream or filter function to handle the output.\n\
  1274.  BUFFER may be also nil, meaning that this process is not associated\n\
  1275.  with any buffer\n\
  1276. Third arg is name of the host to connect to.\n\
  1277. Fourth arg SERVICE is name of the service desired, or an integer\n\
  1278.  specifying a port number to connect to.")
  1279.    (name, buffer, host, service)
  1280.       Lisp_Object name, buffer, host, service;
  1281. {
  1282.   Lisp_Object proc;
  1283.   register int i;
  1284.   struct sockaddr_in address;
  1285.   struct servent *svc_info;
  1286.   struct hostent *host_info;
  1287.   int s, outch, inch;
  1288.   char errstring[80];
  1289.   int port;
  1290.   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
  1291.  
  1292.   GCPRO4 (name, buffer, host, service);
  1293.   CHECK_STRING (name, 0);
  1294.   CHECK_STRING (host, 0);
  1295.   if (XTYPE(service) == Lisp_Int)
  1296.     port = htons ((unsigned short) XINT (service));
  1297.   else
  1298.     {
  1299.       CHECK_STRING (service, 0);
  1300.       svc_info = getservbyname (XSTRING (service)->data, "tcp");
  1301.       if (svc_info == 0)
  1302.     error ("Unknown service \"%s\"", XSTRING (service)->data);
  1303.       port = svc_info->s_port;
  1304.     }
  1305.  
  1306.   host_info = gethostbyname (XSTRING (host)->data);
  1307.   if (host_info == 0)
  1308.     error ("Unknown host \"%s\"", XSTRING(host)->data);
  1309.  
  1310.   bzero (&address, sizeof address);
  1311.   bcopy (host_info->h_addr, (char *) &address.sin_addr, host_info->h_length);
  1312.   address.sin_family = host_info->h_addrtype;
  1313.   address.sin_port = port;
  1314.  
  1315.   s = socket (host_info->h_addrtype, SOCK_STREAM, 0);
  1316.   if (s < 0) 
  1317.     report_file_error ("error creating socket", Fcons (name, Qnil));
  1318.  
  1319.   if (connect (s, &address, sizeof address) == -1)
  1320.     {
  1321.       close (s);
  1322.       error ("Host \"%s\" not responding", XSTRING (host)->data);
  1323.     }
  1324.  
  1325.   inch = s;
  1326.   outch = dup (s);
  1327.   if (outch < 0) 
  1328.     report_file_error ("error duplicating socket", Fcons (name, Qnil));
  1329.  
  1330.   if (!NULL (buffer))
  1331.     buffer = Fget_buffer_create (buffer);
  1332.   proc = make_process (name);
  1333.  
  1334.   chan_process[inch] = proc;
  1335.  
  1336. #ifdef O_NONBLOCK
  1337.   fcntl (inch, F_SETFL, O_NONBLOCK);
  1338. #else
  1339. #ifdef O_NDELAY
  1340.   fcntl (inch, F_SETFL, O_NDELAY);
  1341. #endif
  1342. #endif
  1343.  
  1344.   XPROCESS (proc)->childp = host;
  1345.   XPROCESS (proc)->command_channel_p = Qnil;
  1346.   XPROCESS (proc)->buffer = buffer;
  1347.   XPROCESS (proc)->sentinel = Qnil;
  1348.   XPROCESS (proc)->filter = Qnil;
  1349.   XPROCESS (proc)->command = Qnil;
  1350.   XPROCESS (proc)->pid = Qnil;
  1351.   XPROCESS (proc)->kill_without_query = Qt;
  1352.   XFASTINT (XPROCESS (proc)->infd) = s;
  1353.   XFASTINT (XPROCESS (proc)->outfd) = outch;
  1354.   XPROCESS (proc)->status = Qrun;
  1355.   FD_SET (inch, &input_wait_mask);
  1356.  
  1357.   UNGCPRO;
  1358.   return proc;
  1359. }
  1360. #endif    /* HAVE_SOCKETS */
  1361.  
  1362. deactivate_process (proc)
  1363.      Lisp_Object proc;
  1364. {
  1365.   register int inchannel, outchannel;
  1366.   register struct Lisp_Process *p = XPROCESS (proc);
  1367.  
  1368.   inchannel = XFASTINT (p->infd);
  1369.   outchannel = XFASTINT (p->outfd);
  1370.  
  1371.   if (inchannel)
  1372.     {
  1373.       /* Beware SIGCHLD hereabouts. */
  1374.       flush_pending_output (inchannel);
  1375.       close (inchannel);
  1376.       if (outchannel  &&  outchannel != inchannel)
  1377.      close (outchannel);
  1378.  
  1379.       XFASTINT (p->infd) = 0;
  1380.       XFASTINT (p->outfd) = 0;
  1381.       chan_process[inchannel] = Qnil;
  1382.       FD_CLR (inchannel, &input_wait_mask);
  1383.     }
  1384. }
  1385.  
  1386. /* Close all descriptors currently in use for communication
  1387.    with subprocess.  This is used in a newly-forked subprocess
  1388.    to get rid of irrelevant descriptors.  */
  1389.  
  1390. close_process_descs ()
  1391. {
  1392.   int i;
  1393.   for (i = 0; i < MAXDESC; i++)
  1394.     {
  1395.       Lisp_Object process;
  1396.       process = chan_process[i];
  1397.       if (!NULL (process))
  1398.     {
  1399.       int in = XFASTINT (XPROCESS (process)->infd);
  1400.       int out = XFASTINT (XPROCESS (process)->outfd);
  1401.       close (in);
  1402.       if (in != out)
  1403.         close (out);
  1404.     }
  1405.     }
  1406. }
  1407.  
  1408. DEFUN ("accept-process-output", Faccept_process_output, Saccept_process_output,
  1409.   0, 1, 0,
  1410.   "Allow any pending output from subprocesses to be read by Emacs.\n\
  1411. It is read into the process' buffers or given to their filter functions.\n\
  1412. Non-nil arg PROCESS means do not return until some output has been received\n\
  1413. from PROCESS.")
  1414.   (proc)
  1415.      register Lisp_Object proc;
  1416. {
  1417.   if (NULL (proc))
  1418.     wait_reading_process_input (-1, 0, 0);
  1419.   else
  1420.     {
  1421.       proc = get_process (proc);
  1422.       wait_reading_process_input (0, XPROCESS (proc), 0);
  1423.     }
  1424.   return Qnil;
  1425. }
  1426.  
  1427. /* This variable is different from waiting_for_input in keyboard.c.
  1428.    It is used to communicate to a lisp process-filter/sentinel (via the
  1429.    function Fwaiting_for_user_input_p below) whether emacs was waiting
  1430.    for user-input when that process-filter was called.
  1431.    waiting_for_input cannot be used as that is by definition 0 when
  1432.    lisp code is being evalled */
  1433. static int waiting_for_user_input_p;
  1434.  
  1435. /* Read and dispose of subprocess output
  1436.  while waiting for timeout to elapse and/or keyboard input to be available.
  1437.  
  1438.  time_limit is the timeout in seconds, or zero for no limit.
  1439.  -1 means gobble data available immediately but don't wait for any.
  1440.  
  1441.  read_kbd is 1 to return when input is available.
  1442.  -1 means caller will actually read the input.
  1443.  A pointer to a struct Lisp_Process means wait until
  1444.  something arrives from that process.
  1445.  
  1446.  do_display means redisplay should be done to show
  1447.  subprocess output that arrives.  */
  1448.  
  1449. wait_reading_process_input (time_limit, read_kbd, do_display)
  1450.      int time_limit, read_kbd, do_display;
  1451. {
  1452.   register int channel, nfds, m;
  1453.   SELECT_TYPE Available;
  1454.   SELECT_TYPE Exception;
  1455.   int xerrno;
  1456.   Lisp_Object proc;
  1457. #ifdef HAVE_TIMEVAL
  1458.   struct timeval timeout, end_time, garbage;
  1459. #else
  1460.   long timeout, end_time, temp;
  1461. #endif /* not HAVE_TIMEVAL */
  1462.   SELECT_TYPE Atemp;
  1463.   int wait_channel = 0;
  1464.   struct Lisp_Process *wait_proc = 0;
  1465.   extern kbd_count;
  1466.  
  1467.   /* Detect when read_kbd is really the address of a Lisp_Process.  */
  1468.   if (read_kbd > 10 || read_kbd < -1)
  1469.     {
  1470.       wait_proc = (struct Lisp_Process *) read_kbd;
  1471.       wait_channel = XFASTINT (wait_proc->infd);
  1472.       read_kbd = 0;
  1473.     }
  1474.   waiting_for_user_input_p = read_kbd;
  1475.  
  1476.   /* Since we may need to wait several times,
  1477.      compute the absolute time to return at.  */
  1478.   if (time_limit)
  1479.     {
  1480. #ifdef HAVE_TIMEVAL
  1481.       gettimeofday (&end_time, &garbage);
  1482.       end_time.tv_sec += time_limit;
  1483. #else /* not HAVE_TIMEVAL */
  1484.       time (&end_time);
  1485.       end_time += time_limit;
  1486. #endif /* not HAVE_TIMEVAL */
  1487.     }
  1488.  
  1489. #if 0  /* Select emulator claims to preserve alarms.
  1490.       And there are many ways to get out of this function by longjmp.  */
  1491.   /* Turn off periodic alarms (in case they are in use)
  1492.      because the select emulator uses alarms.  */
  1493.   stop_polling ();
  1494. #endif
  1495.  
  1496.   while (1)
  1497.     {
  1498.       /* If calling from keyboard input, do not quit
  1499.      since we want to return C-g as an input character.
  1500.      Otherwise, do pending quit if requested.  */
  1501.       if (read_kbd >= 0)
  1502.     {
  1503. #if 0
  1504.       /* This is the same condition tested by QUIT.
  1505.          We need to resume polling if we are going to quit.  */
  1506.       if (!NULL (Vquit_flag) && NULL (Vinhibit_quit))
  1507.         {
  1508.           start_polling ();
  1509.           QUIT;
  1510.         }
  1511. #endif
  1512.       QUIT;
  1513.     }
  1514.  
  1515.       /* If status of something has changed, and no input is available,
  1516.      notify the user of the change right away */
  1517.       if (update_tick != process_tick && do_display)
  1518.     {
  1519.       Atemp = input_wait_mask;
  1520. #ifdef HAVE_TIMEVAL
  1521.       timeout.tv_sec=0; timeout.tv_usec=0;
  1522. #else /* not HAVE_TIMEVAL */
  1523.       timeout = 0;
  1524. #endif /* not HAVE_TIMEVAL */
  1525.       if (select (MAXDESC, &Atemp, 0, 0, &timeout) <= 0)
  1526.         status_notify ();
  1527.     }
  1528.  
  1529.       /* Don't wait for output from a non-running process.  */
  1530.       if (wait_proc != 0 && !NULL (wait_proc->raw_status_low))
  1531.     update_status (wait_proc);
  1532.       if (wait_proc != 0
  1533.       && ! EQ (wait_proc->status, Qrun))
  1534.     break;
  1535.  
  1536.       if (fix_screen_hook)
  1537.     (*fix_screen_hook) ();
  1538.  
  1539.       /* Compute time from now till when time limit is up */
  1540.       /* Exit if already run out */
  1541.       if (time_limit == -1)
  1542.     {
  1543.       /* -1 specified for timeout means
  1544.          gobble output available now
  1545.          but don't wait at all. */
  1546. #ifdef HAVE_TIMEVAL
  1547.       timeout.tv_sec = 0;
  1548.       timeout.tv_usec = 0;
  1549. #else
  1550.       timeout = 0;
  1551. #endif /* not HAVE_TIMEVAL */
  1552.     }
  1553.       else if (time_limit)
  1554.     {
  1555. #ifdef HAVE_TIMEVAL
  1556.       gettimeofday (&timeout, &garbage);
  1557.       timeout.tv_sec = end_time.tv_sec - timeout.tv_sec;
  1558.       timeout.tv_usec = end_time.tv_usec - timeout.tv_usec;
  1559.       if (timeout.tv_usec < 0)
  1560.         timeout.tv_usec += 1000000,
  1561.         timeout.tv_sec--;
  1562.       if (timeout.tv_sec < 0)
  1563.         break;
  1564. #else /* not HAVE_TIMEVAL */
  1565.           time (&temp);
  1566.       timeout = end_time - temp;
  1567.       if (timeout < 0)
  1568.         break;
  1569. #endif /* not HAVE_TIMEVAL */
  1570.     }
  1571.       else
  1572.     {
  1573. #ifdef HAVE_TIMEVAL
  1574.       /* If no real timeout, loop sleeping with a big timeout
  1575.          so that input interrupt can wake us up by zeroing it  */
  1576.       timeout.tv_sec = 100;
  1577.       timeout.tv_usec = 0;
  1578. #else /* not HAVE_TIMEVAL */
  1579.           timeout = 100000;    /* 100000 recognized by the select emulator */
  1580. #endif /* not HAVE_TIMEVAL */
  1581.     }
  1582.  
  1583.       /* Cause quitting and alarm signals to take immediate action,
  1584.      and cause input available signals to zero out timeout */
  1585.       if (read_kbd < 0)
  1586.     set_waiting_for_input (&timeout);
  1587.  
  1588.       /* Wait till there is something to do */
  1589.  
  1590.       Available = Exception = input_wait_mask;
  1591.       if (!read_kbd)
  1592.     FD_CLR (0, &Available);
  1593.  
  1594.       if (read_kbd && kbd_count)
  1595.     nfds = 0;
  1596.       else
  1597. #ifdef IBMRTAIX
  1598.     nfds = select (MAXDESC, &Available, 0, 0, &timeout);
  1599. #else
  1600. #ifdef HPUX
  1601.     nfds = select (MAXDESC, &Available, 0, 0, &timeout);
  1602. #else
  1603.     nfds = select (MAXDESC, &Available, 0, &Exception, &timeout);
  1604. #endif
  1605. #endif
  1606.       xerrno = errno;
  1607.  
  1608.       if (fix_screen_hook)
  1609.     (*fix_screen_hook) ();
  1610.  
  1611.       /* Make C-g and alarm signals set flags again */
  1612.       clear_waiting_for_input ();
  1613.  
  1614.       /* If we woke up due to SIGWINCH, actually change size now.  */
  1615.       do_pending_window_change ();
  1616.  
  1617.       if (time_limit && nfds == 0)    /* timeout elapsed */
  1618.     break;
  1619.       if (nfds < 0)
  1620.     {
  1621.       if (xerrno == EINTR)
  1622.         FD_ZERO (&Available);
  1623. #ifdef ALLIANT
  1624.       /* This happens for no known reason on ALLIANT.
  1625.          I am guessing that this is the right response. -- RMS.  */
  1626.       else if (xerrno == EFAULT)
  1627.         FD_ZERO (&Available);
  1628. #endif
  1629.       else if (xerrno == EBADF)
  1630. #ifdef AIX
  1631.       /* AIX will return EBADF on a call to select involving a ptc if the
  1632.          associated pts isn't open.  Since this will only happen just as
  1633.          a child is dying, just ignore the situation -- SIGCHLD will come
  1634.          along quite quickly, and after cleanup the ptc will no longer be
  1635.          checked, so this error will stop recurring.  */
  1636.         FD_ZERO (&Available);     /* Cannot depend on values returned.  */
  1637. #else /* not AIX */
  1638.         abort ();
  1639. #endif /* not AIX */
  1640.       else
  1641.         error("select error: %s", sys_errlist[xerrno]);
  1642.     }
  1643. #ifdef sun
  1644.       else if (nfds > 0 && FD_ISSET (0, &Available) && interrupt_input)
  1645.     /* System sometimes fails to deliver SIGIO.  */
  1646.     kill (getpid (), SIGIO);
  1647. #endif
  1648.  
  1649.       /* Check for keyboard input */
  1650.       /* If there is any, return immediately
  1651.      to give it higher priority than subprocesses */
  1652.  
  1653.       if (read_kbd && detect_input_pending ())
  1654.     break;
  1655.  
  1656. #ifdef vipc
  1657.       /* Check for connection from other process */
  1658.  
  1659.       if (FD_ISSET (comm_server, &Available))
  1660.     {
  1661.       FD_CLR (comm_server, &Available);
  1662.       create_commchan ();
  1663.     }
  1664. #endif vipc
  1665.  
  1666.       /* Check for data from a process or a command channel */
  1667.  
  1668.       for (channel = 3; channel < MAXDESC; channel++)
  1669.     {
  1670.       if (FD_ISSET (channel, &Available))
  1671.         {
  1672.           int nread;
  1673.  
  1674.           FD_CLR (channel, &Available);
  1675.           /* If waiting for this channel,
  1676.          arrange to return as soon as no more input
  1677.          to be processed.  No more waiting.  */
  1678.           if (wait_channel == channel)
  1679.         {
  1680.           wait_channel = 0;
  1681.           time_limit = -1;
  1682.         }
  1683.           proc = chan_process[channel];
  1684.           if (NULL (proc))
  1685.         continue;
  1686.  
  1687. #ifdef vipc
  1688.           /* It's a command channel */
  1689.           if (!NULL (XPROCESS (proc)->command_channel_p))
  1690.         {
  1691.           ProcessCommChan (channel, proc);
  1692.           if (NULL (XPROCESS (proc)->command_channel_p))
  1693.             {
  1694.               /* It has ceased to be a command channel! */
  1695.               int bytes_available;
  1696.               if (ioctl (channel, FIONREAD, &bytes_available) < 0)
  1697.             bytes_available = 0;
  1698.               if (bytes_available)
  1699.             FD_SET (channel, &Available);
  1700.             }
  1701.           continue;
  1702.         }
  1703. #endif vipc
  1704.  
  1705.           /* Read data from the process, starting with our
  1706.          buffered-ahead character if we have one.  */
  1707.  
  1708.           nread = read_process_output (proc, channel);
  1709.           if (nread > 0)
  1710.         {
  1711.           /* Since read_process_output can run a filter,
  1712.              which can call accept-process-output,
  1713.              don't try to read from any other processes
  1714.              before doing the select again.  */
  1715.           FD_ZERO (&Available);
  1716.  
  1717.           if (do_display)
  1718.             redisplay_preserve_echo_area ();
  1719.         }
  1720. #ifdef EWOULDBLOCK
  1721.           else if (nread == -1 && errno == EWOULDBLOCK)
  1722.         ;
  1723. #else
  1724. #ifdef O_NONBLOCK
  1725.           else if (nread == -1 && errno == EAGAIN)
  1726.         ;
  1727. #else
  1728. #ifdef O_NDELAY
  1729.           else if (nread == -1 && errno == EAGAIN)
  1730.         ;
  1731.           /* Note that we cannot distinguish between no input
  1732.          available now and a closed pipe.
  1733.          With luck, a closed pipe will be accompanied by
  1734.          subprocess termination and SIGCHLD.  */
  1735.           else if (nread == 0)
  1736.         ;
  1737. #endif /* O_NDELAY */
  1738. #endif /* O_NONBLOCK */
  1739. #endif /* EWOULDBLOCK */
  1740. #ifdef HAVE_PTYS
  1741.           /* On some OSs with ptys, when the process on one end of
  1742.          a pty exits, the other end gets an error reading with
  1743.          errno = EIO instead of getting an EOF (0 bytes read).
  1744.          Therefore, if we get an error reading and errno =
  1745.          EIO, just continue, because the child process has
  1746.          exited and should clean itself up soon (e.g. when we
  1747.          get a SIGCHLD). */
  1748.           else if (nread == -1 && errno == EIO)
  1749.         ;
  1750. #endif /* HAVE_PTYS */
  1751. /* If we can detect process termination, don't consider the process
  1752.    gone just because its pipe is closed.  */
  1753. #ifdef SIGCHLD
  1754.           else if (nread == 0)
  1755.         ;
  1756. #endif
  1757.           else
  1758.         {
  1759.           /* Preserve status of processes already terminated.  */
  1760.           XSETINT (XPROCESS (proc)->tick, ++process_tick);
  1761.           deactivate_process (proc);
  1762.           if (!NULL (XPROCESS (proc)->raw_status_low))
  1763.             update_status (XPROCESS (proc));
  1764.           if (EQ (XPROCESS (proc)->status, Qrun))
  1765.             XPROCESS (proc)->status
  1766.               = Fcons (Qexit, Fcons (make_number (256), Qnil));
  1767.         }
  1768.         }
  1769.     } /* end for */
  1770.     } /* end while */
  1771.  
  1772. #if 0
  1773.   /* Resume periodic signals to poll for input, if necessary.  */
  1774.   start_polling ();
  1775. #endif
  1776. }
  1777.  
  1778. /* Actually call the filter.  This gets the information via variables
  1779.    because internal_condition_case won't pass arguments.  */
  1780.  
  1781. Lisp_Object
  1782. run_filter ()
  1783. {
  1784.   return call2 (this_filter, filter_process, filter_string);
  1785. }
  1786.  
  1787. /* Read pending output from the process channel,
  1788.    starting with our buffered-ahead character if we have one.
  1789.    Yield number of characters read.
  1790.  
  1791.    This function reads at most 1024 characters.
  1792.    If you want to read all available subprocess output,
  1793.    you must call it repeatedly until it returns zero.  */
  1794.  
  1795. read_process_output (proc, channel)
  1796.      Lisp_Object proc;
  1797.      register int channel;
  1798. {
  1799.   register int nchars;
  1800.   char chars[1024];
  1801.   register Lisp_Object outstream;
  1802.   register struct buffer *old = current_buffer;
  1803.   register struct Lisp_Process *p = XPROCESS (proc);
  1804.   register int opoint;
  1805.  
  1806.   if (proc_buffered_char[channel] < 0)
  1807.     nchars = read (channel, chars, sizeof chars);
  1808.   else
  1809.     {
  1810.       chars[0] = proc_buffered_char[channel];
  1811.       proc_buffered_char[channel] = -1;
  1812.       nchars = read (channel, chars + 1, sizeof chars - 1);
  1813.       if (nchars < 0)
  1814.     nchars = 1;
  1815.       else
  1816.     nchars = nchars + 1;
  1817.     }
  1818.  
  1819.   if (nchars <= 0) return nchars;
  1820.  
  1821.   outstream = p->filter;
  1822.   if (!NULL (outstream))
  1823.     {
  1824.       int count = specpdl_ptr - specpdl;
  1825.       specbind (Qinhibit_quit, Qt);
  1826.       this_filter = outstream;
  1827.       filter_process = proc;
  1828.       filter_string = make_string (chars, nchars);
  1829.       call2 (this_filter, filter_process, filter_string);
  1830.       /*   internal_condition_case (run_filter, Qerror, Fidentity);  */
  1831.       unbind_to (count);
  1832.       return nchars;
  1833.     }
  1834.  
  1835.   /* If no filter, write into buffer if it isn't dead.  */
  1836.   if (!NULL (p->buffer) && !NULL (XBUFFER (p->buffer)->name))
  1837.     {
  1838.       Lisp_Object tem;
  1839.  
  1840.       Fset_buffer (p->buffer);
  1841.       opoint = point;
  1842.  
  1843.       /* Insert new output into buffer
  1844.      at the current end-of-output marker,
  1845.      thus preserving logical ordering of input and output.  */
  1846.       if (XMARKER (p->mark)->buffer)
  1847.     SET_PT (marker_position (p->mark));
  1848.       else
  1849.     SET_PT (ZV);
  1850.       if (point <= opoint)
  1851.     opoint += nchars;
  1852.  
  1853.       tem = current_buffer->read_only;
  1854.       current_buffer->read_only = Qnil;
  1855.       insert (chars, nchars);
  1856.       current_buffer->read_only = tem;
  1857.       Fset_marker (p->mark, make_number (point), p->buffer);
  1858.       update_mode_lines++;
  1859.  
  1860.       SET_PT (opoint);
  1861.       set_buffer_internal (old);
  1862.     }
  1863.   return nchars;
  1864. }
  1865.  
  1866. DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p, Swaiting_for_user_input_p,
  1867.        0, 0, 0,
  1868.   "Returns non-NIL if emacs is waiting for input from the user.\n\
  1869. This is intended for use by asynchronous process output filters and sentinels.")
  1870.        ()
  1871. {
  1872.   return ((waiting_for_user_input_p) ? Qt : Qnil);
  1873. }
  1874.  
  1875. /* Sending data to subprocess */
  1876.  
  1877. jmp_buf send_process_frame;
  1878.  
  1879. send_process_trap ()
  1880. {
  1881. #ifdef BSD4_1
  1882.   sigrelse (SIGPIPE);
  1883.   sigrelse (SIGALRM);
  1884. #endif /* BSD4_1 */
  1885.   longjmp (send_process_frame, 1);
  1886. }
  1887.  
  1888. send_process (proc, buf, len)
  1889.      Lisp_Object proc;
  1890.      char *buf;
  1891.      int len;
  1892. {
  1893.   /* Don't use register vars; longjmp can lose them.  */
  1894.   int rv;
  1895.   unsigned char *procname = XSTRING (XPROCESS (proc)->name)->data;
  1896.  
  1897.   if (!NULL (XPROCESS (proc)->raw_status_low))
  1898.     update_status (XPROCESS (proc));
  1899.   if (! EQ (XPROCESS (proc)->status, Qrun))
  1900.     error ("Process %s not running", procname);
  1901.  
  1902.   if (!setjmp (send_process_frame))
  1903.     while (len > 0)
  1904.       {
  1905.     signal (SIGPIPE, send_process_trap);
  1906.     rv = write (XFASTINT (XPROCESS (proc)->outfd), buf, len);
  1907.     signal (SIGPIPE, SIG_DFL);
  1908.     if (rv < 0)
  1909.       {
  1910. #ifdef EWOULDBLOCK
  1911.         if (errno == EWOULDBLOCK)
  1912.           {
  1913.         /* It would be nice to accept process output here,
  1914.            but that is difficult.  For example, it could
  1915.            garbage what we are sending if that is from a buffer.  */
  1916.         immediate_quit = 1;
  1917.         QUIT;
  1918.         sleep (1);
  1919.         immediate_quit = 0;
  1920.         continue;
  1921.           }
  1922. #endif
  1923.         report_file_error ("writing to process", Fcons (proc, Qnil));
  1924.       }
  1925.     buf += rv;
  1926.     len -= rv;
  1927.       }
  1928.   else
  1929.     {
  1930.       XPROCESS (proc)->raw_status_low = Qnil;
  1931.       XPROCESS (proc)->raw_status_high = Qnil;
  1932.       XPROCESS (proc)->status = Fcons (Qexit, Fcons (make_number (256), Qnil));
  1933.       XSETINT (XPROCESS (proc)->tick, ++process_tick);
  1934.       deactivate_process (proc);
  1935.       error ("SIGPIPE raised on process %s; closed it", procname);
  1936.     }
  1937. }
  1938.  
  1939. DEFUN ("process-send-region", Fprocess_send_region, Sprocess_send_region,
  1940.   3, 3, 0,
  1941.   "Send current contents of region as input to PROCESS.\n\
  1942. PROCESS may be a process name.\n\
  1943. Called from program, takes three arguments, PROCESS, START and END.")
  1944.   (process, start, end)
  1945.      Lisp_Object process, start, end;
  1946. {
  1947.   Lisp_Object proc;
  1948.   int start1;
  1949.  
  1950.   proc = get_process (process);
  1951.   validate_region (&start, &end);
  1952.  
  1953.   if (XINT (start) < GPT && XINT (end) > GPT)
  1954.     move_gap (start);
  1955.  
  1956.   start1 = XINT (start);
  1957.   send_process (proc, &FETCH_CHAR (start1), XINT (end) - XINT (start));
  1958.  
  1959.   return Qnil;
  1960. }
  1961.  
  1962. DEFUN ("process-send-string", Fprocess_send_string, Sprocess_send_string,
  1963.   2, 2, 0,
  1964.   "Send PROCESS the contents of STRING as input.\n\
  1965. PROCESS may be a process name.")
  1966.   (process, string)
  1967.      Lisp_Object process, string;
  1968. {
  1969.   Lisp_Object proc;
  1970.   CHECK_STRING (string, 1);
  1971.   proc = get_process (process);
  1972.   send_process (proc, XSTRING (string)->data, XSTRING (string)->size);
  1973.   return Qnil;
  1974. }
  1975.  
  1976. /* send a signal number SIGNO to PROCESS.
  1977.    CURRENT_GROUP means send to the process group that currently owns
  1978.    the terminal being used to communicate with PROCESS.
  1979.    This is used for various commands in shell mode.
  1980.    If NOMSG is zero, insert signal-announcements into process's buffers
  1981.    right away.  */
  1982.  
  1983. process_send_signal (process, signo, current_group, nomsg)
  1984.      Lisp_Object process;
  1985.      int signo;
  1986.      Lisp_Object current_group;
  1987.      int nomsg;
  1988. {
  1989.   Lisp_Object proc;
  1990.   register struct Lisp_Process *p;
  1991.   int gid;
  1992.  
  1993.   proc = get_process (process);
  1994.   p = XPROCESS (proc);
  1995.  
  1996.   if (!EQ (p->childp, Qt))
  1997.     error ("Process %s is not a subprocess",
  1998.        XSTRING (p->name)->data);
  1999.   if (!XFASTINT (p->infd))
  2000.     error ("Process %s is not active",
  2001.        XSTRING (p->name)->data);
  2002.  
  2003.   if (NULL (p->pty_flag))
  2004.     current_group = Qnil;
  2005.  
  2006. #ifdef TIOCGPGRP        /* Not sure about this! (fnf) */
  2007.   /* If we are using pgrps, get a pgrp number and make it negative.  */
  2008.   if (!NULL (current_group))
  2009.     {
  2010.       ioctl (XFASTINT (p->infd), TIOCGPGRP, &gid);
  2011.       gid = - gid;
  2012.     }
  2013.   else
  2014.     gid = - XFASTINT (p->pid);
  2015. #else /* not using pgrps */
  2016.   /* Can't select pgrps on this system, so we know that
  2017.      the child itself heads the pgrp.  */
  2018.   gid = - XFASTINT (p->pid);
  2019. #endif /* not using pgrps */
  2020.  
  2021.   switch (signo)
  2022.     {
  2023. #ifdef SIGCONT
  2024.     case SIGCONT:
  2025.       p->raw_status_low = Qnil;
  2026.       p->raw_status_high = Qnil;
  2027.       p->status = Qrun;
  2028.       XSETINT (p->tick, ++process_tick);
  2029.       if (!nomsg)
  2030.     status_notify ();
  2031.       break;
  2032. #endif
  2033.     case SIGINT:
  2034.     case SIGQUIT:
  2035.     case SIGKILL:
  2036.       flush_pending_output (XFASTINT (p->infd));
  2037.       break;
  2038.     }
  2039.   /* gid may be a pid, or minus a pgrp's number */
  2040. #ifdef TIOCSIGSEND
  2041.   if (!NULL (current_group))
  2042.     ioctl (XFASTINT (p->infd), TIOCSIGSEND, signo);
  2043.   else
  2044.     {
  2045.       gid = - XFASTINT (p->pid);
  2046.       kill (gid, signo);
  2047.     }
  2048. #else /* no TIOCSIGSEND */
  2049. #ifdef BSD
  2050.   /* On bsd, [man says] kill does not accept a negative number to kill a pgrp.
  2051.      Must do that differently.  */
  2052.   killpg (-gid, signo);
  2053. #else /* Not BSD.  */
  2054.   kill (gid, signo);
  2055. #endif /* Not BSD.  */
  2056. #endif /* no TIOCSIGSEND */
  2057. }
  2058.  
  2059. DEFUN ("interrupt-process", Finterrupt_process, Sinterrupt_process, 0, 2, 0,
  2060.   "Interrupt process PROCESS.  May be process or name of one.\n\
  2061. Nil or no arg means current buffer's process.\n\
  2062. Second arg CURRENT-GROUP non-nil means send signal to\n\
  2063. the current process-group of the process's controlling terminal\n\
  2064. rather than to the process's own process group.\n\
  2065. If the process is a shell, this means interrupt current subjob\n\
  2066. rather than the shell.")
  2067.   (process, current_group)
  2068.      Lisp_Object process, current_group;
  2069. {
  2070.   process_send_signal (process, SIGINT, current_group, 0);
  2071.   return process;
  2072. }
  2073.  
  2074. DEFUN ("kill-process", Fkill_process, Skill_process, 0, 2, 0,
  2075.   "Kill process PROCESS.  May be process or name of one.\n\
  2076. See function interrupt-process for more details on usage.")
  2077.   (process, current_group)
  2078.      Lisp_Object process, current_group;
  2079. {
  2080.   process_send_signal (process, SIGKILL, current_group, 0);
  2081.   return process;
  2082. }
  2083.  
  2084. DEFUN ("quit-process", Fquit_process, Squit_process, 0, 2, 0,
  2085.   "Send QUIT signal to process PROCESS.  May be process or name of one.\n\
  2086. See function interrupt-process for more details on usage.")
  2087.   (process, current_group)
  2088.      Lisp_Object process, current_group;
  2089. {
  2090.   process_send_signal (process, SIGQUIT, current_group, 0);
  2091.   return process;
  2092. }
  2093.  
  2094. DEFUN ("stop-process", Fstop_process, Sstop_process, 0, 2, 0,
  2095.   "Stop process PROCESS.  May be process or name of one.\n\
  2096. See function interrupt-process for more details on usage.")
  2097.   (process, current_group)
  2098.      Lisp_Object process, current_group;
  2099. {
  2100. #ifndef SIGTSTP
  2101.   error ("no SIGTSTP support");
  2102. #else
  2103.   process_send_signal (process, SIGTSTP, current_group, 0);
  2104. #endif
  2105.   return process;
  2106. }
  2107.  
  2108. DEFUN ("continue-process", Fcontinue_process, Scontinue_process, 0, 2, 0,
  2109.   "Continue process PROCESS.  May be process or name of one.\n\
  2110. See function interrupt-process for more details on usage.")
  2111.   (process, current_group)
  2112.      Lisp_Object process, current_group;
  2113. {
  2114. #ifdef SIGCONT
  2115.     process_send_signal (process, SIGCONT, current_group, 0);
  2116. #else
  2117.     error ("no SIGCONT support");
  2118. #endif
  2119.   return process;
  2120. }
  2121.  
  2122. DEFUN ("process-send-eof", Fprocess_send_eof, Sprocess_send_eof, 0, 1, 0,
  2123.   "Make PROCESS see end-of-file in its input.\n\
  2124. Eof comes after any text already sent to it.\n\
  2125. nil or no arg means current buffer's process.")
  2126.   (process)
  2127.      Lisp_Object process;
  2128. {
  2129.   Lisp_Object proc;
  2130.  
  2131.   proc = get_process (process);
  2132.   /* Sending a zero-length record is supposed to mean eof
  2133.      when TIOCREMOTE is turned on.  */
  2134. #ifdef DID_REMOTE
  2135.   {
  2136.     char buf[1];
  2137.     write (XFASTINT (XPROCESS (proc)->outfd), buf, 0);
  2138.   }
  2139. #else /* did not do TOICREMOTE */
  2140.   send_process (proc, "\004", 1);
  2141. #endif /* did not do TOICREMOTE */
  2142.   return process;
  2143. }
  2144.  
  2145. /* Kill all processes associated with `buffer'.
  2146.  If `buffer' is nil, kill all processes  */
  2147.  
  2148. kill_buffer_processes (buffer)
  2149.      Lisp_Object buffer;
  2150. {
  2151.   Lisp_Object tail, proc;
  2152.  
  2153.   for (tail = Vprocess_alist; XGCTYPE (tail) == Lisp_Cons;
  2154.        tail = XCONS (tail)->cdr)
  2155.     {
  2156.       proc = XCONS (XCONS (tail)->car)->cdr;
  2157.       if (XGCTYPE (proc) == Lisp_Process
  2158.       && (NULL (buffer) || EQ (XPROCESS (proc)->buffer, buffer)))
  2159.     {
  2160.       if (NETCONN_P (proc))
  2161.         deactivate_process (proc);
  2162.       else if (XFASTINT (XPROCESS (proc)->infd))
  2163.         process_send_signal (proc, SIGHUP, Qnil, 1);
  2164.     }
  2165.     }
  2166. }
  2167.  
  2168. /* On receipt of a signal that a child status has changed,
  2169.  loop asking about children with changed statuses until
  2170.  the system says there are no more.
  2171.    All we do is change the status;
  2172.  we do not run sentinels or print notifications.
  2173.  That is saved for the next time keyboard input is done,
  2174.  in order to avoid timing errors.  */
  2175.  
  2176. /** WARNING: this can be called during garbage collection.
  2177.  Therefore, it must not be fooled by the presence of mark bits in
  2178.  Lisp objects.  */
  2179.  
  2180. /** USG WARNING:  Although it is not obvious from the documentation
  2181.  in signal(2), on a USG system the SIGCLD handler MUST NOT call
  2182.  signal() before executing at least one wait(), otherwise the handler
  2183.  will be called again, resulting in an infinite loop.  The relevant
  2184.  portion of the documentation reads "SIGCLD signals will be queued
  2185.  and the signal-catching function will be continually reentered until
  2186.  the queue is empty".  Invoking signal() causes the kernel to reexamine
  2187.  the SIGCLD queue.   Fred Fish, UniSoft Systems Inc. */
  2188.  
  2189. sigchld_handler (signo)
  2190.      int signo;
  2191. {
  2192.   int old_errno = errno;
  2193.   Lisp_Object proc;
  2194.   register struct Lisp_Process *p;
  2195.  
  2196. #ifdef BSD4_1
  2197.   extern int synch_process_pid;
  2198.   extern int sigheld;
  2199.   sigheld |= sigbit (SIGCHLD);
  2200. #endif
  2201.  
  2202.   while (1)
  2203.     {
  2204.       register int pid;
  2205.       WAITTYPE w;
  2206.       Lisp_Object tail;
  2207.  
  2208. #ifdef WNOHANG
  2209. #ifndef WUNTRACED
  2210. #define WUNTRACED 0
  2211. #endif /* no WUNTRACED */
  2212.       /* Keep trying to get a status until we get a definitive result.  */
  2213.       do 
  2214.     {
  2215.       errno = 0;
  2216.       pid = wait3 (&w, WNOHANG | WUNTRACED, 0);
  2217.     }
  2218.       while (pid <= 0 && errno == EINTR);
  2219.  
  2220.       if (pid <= 0)
  2221.     {
  2222.       /* A real failure.  We have done all our job, so return.  */
  2223.  
  2224.       /* USG systems forget handlers when they are used;
  2225.          must reestablish each time */
  2226. #ifdef USG
  2227.       signal (signo, sigchld_handler);   /* WARNING - must come after wait3() */
  2228. #endif
  2229. #ifdef  BSD4_1
  2230.       sigheld &= ~sigbit (SIGCHLD);
  2231.       sigrelse (SIGCHLD);
  2232. #endif
  2233.       errno = old_errno;
  2234.       return;
  2235.     }
  2236. #else
  2237.       pid = wait (&w);
  2238. #endif /* no WNOHANG */
  2239.  
  2240. #ifdef BSD4_1
  2241.       if (synch_process_pid == pid)
  2242.     synch_process_pid = 0;         /* Zero it to show process has died. */
  2243. #endif
  2244.  
  2245.       /* Find the process that signaled us, and record its status.  */
  2246.  
  2247.       p = 0;
  2248.       for (tail = Vprocess_alist; XSYMBOL (tail) != XSYMBOL (Qnil); tail = XCONS (tail)->cdr)
  2249.     {
  2250.       proc = XCONS (XCONS (tail)->car)->cdr;
  2251.       p = XPROCESS (proc);
  2252.       if (EQ (p->childp, Qt) && XFASTINT (p->pid) == pid)
  2253.         break;
  2254.       p = 0;
  2255.     }
  2256.  
  2257.       /* If we don't recognize the pid number,
  2258.      look for a process being created.  */
  2259.  
  2260.       if (p == 0)
  2261.     for (tail = Vprocess_alist; XSYMBOL (tail) != XSYMBOL (Qnil); tail = XCONS (tail)->cdr)
  2262.       {
  2263.         proc = XCONS (XCONS (tail)->car)->cdr;
  2264.         p = XPROCESS (proc);
  2265.         if (XINT (p->pid) == -1)
  2266.           break;
  2267.         p = 0;
  2268.       }
  2269.  
  2270.       /* Change the status of the process that was found.  */
  2271.  
  2272.       if (p != 0)
  2273.     {
  2274.       union { int i; WAITTYPE wt; } u;
  2275.  
  2276.       XSETINT (p->tick, ++process_tick);
  2277.       u.wt = w;
  2278.       XFASTINT (p->raw_status_low) = u.i & 0xffff;
  2279.       XFASTINT (p->raw_status_high) = u.i >> 16;
  2280.  
  2281.       /* If process has terminated, stop waiting for its output.  */
  2282.       if (WIFSIGNALED (w) || WIFEXITED (w))
  2283.         if (p->infd)
  2284.           FD_CLR (p->infd, &input_wait_mask);
  2285.     }
  2286.  
  2287.       /* On some systems, we must return right away.
  2288.      If any more processes want to signal us, we will
  2289.      get another signal.
  2290.      Otherwise (on systems that have WNOHANG), loop around
  2291.      to use up all the processes that have something to tell us.  */
  2292. #if defined (USG) && ! (defined (HPUX) && defined (WNOHANG))
  2293. #ifdef USG
  2294.       signal (signo, sigchld_handler);
  2295. #endif
  2296.       errno = old_errno;
  2297.       return;
  2298. #endif /* USG, but not HPUX with WNOHANG */
  2299.     }
  2300. }
  2301.  
  2302. /* Report all recent events of a change in process status
  2303.    (either run the sentinel or output a message).
  2304.    This is done while Emacs is waiting for keyboard input.  */
  2305.  
  2306. status_notify ()
  2307. {
  2308.   register Lisp_Object tail, proc, buffer;
  2309.  
  2310.   for (tail = Vprocess_alist; !NULL (tail); tail = Fcdr (tail))
  2311.     {
  2312.       Lisp_Object symbol, msg;
  2313.       register struct Lisp_Process *p;
  2314.  
  2315.       proc = Fcdr (Fcar (tail));
  2316.       p = XPROCESS (proc);
  2317.  
  2318.       if (XINT (p->tick) != XINT (p->update_tick))
  2319.     {
  2320.       struct gcpro gcpro1;
  2321.  
  2322.       XSETINT (p->update_tick, XINT (p->tick));
  2323.  
  2324.       /* If process is still active, read any output that remains.  */
  2325.       if (XFASTINT (p->infd))
  2326.         while (read_process_output (proc, XFASTINT (p->infd)) > 0);
  2327.  
  2328.       buffer = p->buffer;
  2329.  
  2330.       /* Get the text to use for the message.  */
  2331.       if (!NULL (p->raw_status_low))
  2332.         update_status (p);
  2333.       msg = status_message (p->status);
  2334.       GCPRO1 (msg);
  2335.  
  2336.       /* If process is terminated, deactivate it or delete it.  */
  2337.       symbol = p->status;
  2338.       if (XTYPE (p->status) == Lisp_Cons)
  2339.         symbol = XCONS (p->status)->car;
  2340.  
  2341.       if (EQ (symbol, Qsignal) || EQ (symbol, Qexit)
  2342.           || EQ (symbol, Qclosed))
  2343.         {
  2344.           if (delete_exited_processes)
  2345.         remove_process (proc);
  2346.           else
  2347.         deactivate_process (proc);
  2348.         }
  2349.       UNGCPRO;
  2350.  
  2351.       /* Now output the message suitably.  */
  2352.       if (!NULL (p->sentinel))
  2353.         exec_sentinel (proc, msg);
  2354.       /* Don't bother with a message in the buffer
  2355.          when a process becomes runnable.  */
  2356.       else if (!EQ (symbol, Qrun) && !NULL (buffer))
  2357.         {
  2358.           Lisp_Object ro = XBUFFER (buffer)->read_only;
  2359.           Lisp_Object tem;
  2360.           struct buffer *old = current_buffer;
  2361.           int opoint;
  2362.  
  2363.           /* Avoid error if buffer is deleted
  2364.          (probably that's why the process is dead, too) */
  2365.           if (NULL (XBUFFER (buffer)->name))
  2366.         continue;
  2367.           Fset_buffer (buffer);
  2368.           opoint = point;
  2369.           /* Insert new output into buffer
  2370.          at the current end-of-output marker,
  2371.          thus preserving logical ordering of input and output.  */
  2372.           if (XMARKER (p->mark)->buffer)
  2373.         SET_PT (marker_position (p->mark));
  2374.           else
  2375.         SET_PT (ZV);
  2376.           if (point <= opoint)
  2377.         opoint += XSTRING (msg)->size + XSTRING (p->name)->size + 10;
  2378.  
  2379.           tem = current_buffer->read_only;
  2380.           current_buffer->read_only = Qnil;
  2381.           GCPRO1 (msg);
  2382.           InsStr ("\nProcess ");
  2383.           Finsert (1, &p->name);
  2384.           InsStr (" ");
  2385.           Finsert (1, &msg);
  2386.           current_buffer->read_only = tem;
  2387.           Fset_marker (p->mark, make_number (point), p->buffer);
  2388.           UNGCPRO;
  2389.  
  2390.           SET_PT (opoint);
  2391.           set_buffer_internal (old);
  2392.         }
  2393.     }
  2394.     } /* end for */
  2395.  
  2396.   update_mode_lines++;  /* in case buffers use %s in mode-line-format */
  2397.   redisplay_preserve_echo_area ();
  2398.  
  2399.   update_tick = process_tick;
  2400. }
  2401.  
  2402. exec_sentinel (proc, reason)
  2403.      Lisp_Object proc, reason;
  2404. {
  2405.   Lisp_Object sentinel;
  2406.   register struct Lisp_Process *p = XPROCESS (proc);
  2407.   int count = specpdl_ptr - specpdl;
  2408.  
  2409.   sentinel = p->sentinel;
  2410.   if (NULL (sentinel))
  2411.     return;
  2412.  
  2413.   p->sentinel = Qnil;
  2414.   specbind (Qinhibit_quit, Qt);
  2415.   this_filter = sentinel;
  2416.   filter_process = proc;
  2417.   filter_string = reason;
  2418.   call2 (this_filter, filter_process, filter_string);
  2419. /*   internal_condition_case (run_filter, Qerror, Fidentity);  */
  2420.   unbind_to (count);
  2421.   p->sentinel = sentinel;
  2422. }
  2423.  
  2424. init_process ()
  2425. {
  2426.   register int i;
  2427.  
  2428. #ifdef SIGCHLD
  2429. #ifndef CANNOT_DUMP
  2430.   if (! noninteractive || initialized)
  2431. #endif
  2432.     signal (SIGCHLD, sigchld_handler);
  2433. #endif
  2434.  
  2435.   FD_ZERO (&input_wait_mask);
  2436.   FD_SET (0, &input_wait_mask);
  2437.   Vprocess_alist = Qnil;
  2438.   for (i = 0; i < MAXDESC; i++)
  2439.     {
  2440.       chan_process[i] = Qnil;
  2441.       proc_buffered_char[i] = -1;
  2442.     }
  2443. }
  2444.  
  2445. syms_of_process ()
  2446. {
  2447.   Qprocessp = intern ("processp");
  2448.   staticpro (&Qprocessp);
  2449.   Qrun = intern ("run");
  2450.   staticpro (&Qrun);
  2451.   Qstop = intern ("stop");
  2452.   staticpro (&Qstop);
  2453.   Qsignal = intern ("signal");
  2454.   staticpro (&Qsignal);
  2455.   Qexit = intern ("exit");
  2456.   staticpro (&Qexit);
  2457.   Qopen = intern ("open");
  2458.   staticpro (&Qopen);
  2459.   Qclosed = intern ("closed");
  2460.   staticpro (&Qclosed);
  2461.  
  2462.   staticpro (&Vprocess_alist);
  2463.  
  2464.   DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes,
  2465.     "*Non-nil means delete processes immediately when they exit.\n\
  2466. nil means don't delete them until `list-processes' is run.");
  2467.  
  2468.   delete_exited_processes = 1;
  2469.  
  2470.   DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type,
  2471.     "Control type of device used to communicate with subprocesses.\n\
  2472. Values are nil to use a pipe, t for a pty (or pipe if ptys not supported).\n\
  2473. Value takes effect when `start-process' is called.");
  2474.   Vprocess_connection_type = Qt;
  2475.  
  2476.   defsubr (&Sprocessp);
  2477.   defsubr (&Sget_process);
  2478.   defsubr (&Sget_buffer_process);
  2479.   defsubr (&Sdelete_process);
  2480.   defsubr (&Sprocess_status);
  2481.   defsubr (&Sprocess_exit_status);
  2482.   defsubr (&Sprocess_id);
  2483.   defsubr (&Sprocess_name);
  2484.   defsubr (&Sprocess_command);
  2485.   defsubr (&Sset_process_buffer);
  2486.   defsubr (&Sprocess_buffer);
  2487.   defsubr (&Sprocess_mark);
  2488.   defsubr (&Sset_process_filter);
  2489.   defsubr (&Sprocess_filter);
  2490.   defsubr (&Sset_process_sentinel);
  2491.   defsubr (&Sprocess_sentinel);
  2492.   defsubr (&Sprocess_kill_without_query);
  2493.   defsubr (&Slist_processes);
  2494.   defsubr (&Sprocess_list);
  2495.   defsubr (&Sstart_process);
  2496. #ifdef HAVE_SOCKETS
  2497.   defsubr (&Sopen_network_stream);
  2498. #endif /* HAVE_SOCKETS */
  2499.   defsubr (&Saccept_process_output);
  2500.   defsubr (&Sprocess_send_region);
  2501.   defsubr (&Sprocess_send_string);
  2502.   defsubr (&Sinterrupt_process);
  2503.   defsubr (&Skill_process);
  2504.   defsubr (&Squit_process);
  2505.   defsubr (&Sstop_process);
  2506.   defsubr (&Scontinue_process);
  2507.   defsubr (&Sprocess_send_eof);
  2508.   defsubr (&Swaiting_for_user_input_p);
  2509. }
  2510.  
  2511. #endif subprocesses
  2512.